#!/usr/bin/env ruby


def getOption(option)
  File.open('/etc/ejabberd/ssconfig.cfg', 'r') do |f1|  
    while line = f1.gets  
      line = line.gsub(/\n/,'')
      if line.match(/^#/)
        #Comments
      elsif line.match(/^#{option}/)
        return line.gsub(/#{option}/,'')
      end  
    end  
  end
  return "Undefined"
end




source_path = getOption("source_path=")

if source_path == "Undefined"
 #puts "mod_sspresence source_path in undefined: define source_path in /etc/ejabberd/ssconfig.cfg to compile mod_sspresence"
 puts "mod_sspresence source_path in undefined: Exit compile"
else
  puts "Compile mod_sspresence"
  system("erlc #{source_path}/mod_sspresence.erl")
  system 'sudo mv mod_sspresence.beam /lib/ejabberd/ebin/mod_sspresence.beam'
  puts "Compile mod_sspresence OK"
end



